'''
Created on Sep 25, 2013

@author: marchi
'''
import re;
import numpy as np;

class Histo:
    
    def __init__(self,dmin,dmax,dx):
        self.min=dmin;
        self.max=dmax;
        self.dx=dx;
        mm=int((dmax-dmin)/dx)+1;
        self.histo=np.zeros(mm);
        self.count=0;
    def Add(self,value,prob):
        dist=value-self.min;
        m=int(dist/self.dx);       
        self.histo[m]+=prob;
        
    def AddCount(self):
        self.count+=1;

class Cluster:
    '''
    classdocs
    '''
    def __init__(self,ntot,filename):
        p=re.compile('^[0-9][0-9]*::');
        self.Count=0;
        self.totC=0;
        ok=-1;
        self.MAX=ntot+1;
        self.histo=Histo(1,self.MAX,1.0);
        for line in open(filename):
            if p.match(line):
                ok=0;
                Line0=line.split('::');
                Line1=Line0[1].split();
                nAOT=0;
                for o in range((len(Line1)-1)/2):
                    oo=1+2*o+1;
                    if Line1[oo] == 'AOT':
                        nAOT+=1;
                prob=float(nAOT)/float(ntot);     
                self.histo.Add(float(nAOT),prob);
                self.totC+=float(nAOT);
            else:
                if ok == 0:
                    self.Count+=1;
                    self.histo.AddCount();
                    print " %d " % (self.totC)
                ok=1;
    def Prob(self):
        x=self.histo.min;
        myrange=range(len(self.histo.histo));
        
        for n in myrange:
            ele1=float(self.histo.histo[n])/float(self.Count);
            x=n*self.histo.dx+self.histo.min;
            if ele1 == 0:
                continue;
            else:
                print " %f   %f" % (x, ele1);
        
                
        

        